package net.aetherial.context.grounding.estimators.loggers;

import java.io.*;
import java.util.*;

/**
 * An optional companion logger to the regression learner. It logs the internal statistics of a regression to a separate output file for later use and analysis. This
 * information includes coded values and predicted values. 
 */

public class RegressionLogger 
{
	private int fileCount;
	private Writer writer;
	
	/**
	 * Constructor.
	 */
	
	public RegressionLogger ()
	{
		fileCount = 0;
	}

	/**
	 * Resets the logger for recording the properties of a new conversation in a new file.
	 */
	
	public void reset() 
	{
		fileCount++;
	}

	/**
	 * Creates a tab-delimited table of predicted values and coded values. This is useful for generating charts in applications such as Excel for 
	 * studying the performance of the regression versus actual coded values.
	 *  
	 * @param actualValues		List of coded values
	 * @param predictedValues	List of predicted values
	 */
	
	public void log (List<Double> actualValues, List<Double> predictedValues) 
	{
		try 
		{
			writer = new BufferedWriter (new FileWriter (new File ("/Users/cjkarr/Desktop/regression-logs/" + fileCount + ".txt")));

			writer.write ("Prediction\tCoded\n");
			
			for (int i = 0; i < predictedValues.size (); i++)
				writer.write (predictedValues.get (i) + "\t" + actualValues.get (i) + "\n");
			
			writer.close ();
		}
		catch (IOException e) 
		{
			e.printStackTrace();
		}

	}
}
